home *** CD-ROM | disk | FTP | other *** search
- Path: news.wasatch.com!news
- From: rdemanow@wasatch.com (Richard Demanowski)
- Newsgroups: comp.lang.c++,comp.lang.c
- Subject: getch() equivalency help ...
- Date: 20 Jan 1996 00:49:29 GMT
- Organization: wasatch.com
- Message-ID: <4dpe6p$e4j@twin.wasatch.com>
- NNTP-Posting-Host: port23.wasatch.com
-
- I am looking for help with the following question/problem:
-
- I want to have a function that does the same thing as getch() from
- conio.h, but without needing to include conio.h.
-
- This is for a program that will be compiled across about 5 different
- platforms, and the only one that supports conio.h is MS-DOS.
-
- I know a similar function is available in UNIX with the ncurses library,
- but I don't have that on my UNIX box ...
-
- I need a way to do what getch() does, i.e. pause and wait for a SINGLE
- KEYSTROKE and then pass the value of the pressed key back to the calling
- function.
-
- For example:
-
- char incoming=getch();
-
- will pause the program until a single key is pressed and feed the value of
- that key to the char variable incoming.
-
- I would most optimally like to be able to do this using only what's in
- iostream.h or stdio.h, whose functions and operators behave alike across all
- of my target platforms.
-
- I have tried the following:
-
- char incoming=cin.get();
-
- This pauses the program, but allows an entire line to be entered, terminated
- by a newline, and then only the first character of the line is fed to
- incoming, and the rest of the line is available to the next input operation
- on the input stream.
-
- The other version of cin.get() does the same thing:
-
- cin.get(incoming);
-
- I have tried other functions from stdio.h that have the same result as above.
-
- char incoming=getchar();
- char incoming=fgetc(stdin);
-
- I can't seem to find a way to get just a single keystroke in and then flush
- the buffer ...
-
- The only way I have been able to get the behaviour I want is with getch(), and
- it isn't supported on the other target platforms.
-
- If anyone can help, I thank you in advance.
-
- RichD
- rdemanow@wasatch.com
- rjd9404@wcslc.edu
-
- --
- rdemanow@wasatch.com |I am lost. I have gone to look for
- |myself.
- press any key to continue ... |If I should return before I get back,
- press any other key to quit ...|please ask me to wait here.
-
-